<template>
  <el-form :model="form" :label-position="labelPosition" label-width="100px">
    <el-row :gutter="24" class="pl80">
      <el-col>
        <h2>考核信息</h2>
        <el-button size="small" @click="handleShowHistory">历史信息</el-button>
      </el-col>
      <el-col :span="8">
        <el-form-item label="培训名称">
          <el-input v-model="form.name" :style="inputWidth" />
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <el-form-item label="培训开始时间">
          <el-date-picker
            type="date"
            :style="inputWidth"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            v-model="form.startDate"
            @change="handleUpdate"
            placeholder="请选择"
          />
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <el-form-item label="培训结束时间">
          <el-date-picker
            type="date"
            :style="inputWidth"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            v-model="form.endDate"
            @change="handleUpdate"
            placeholder="请选择"
          />
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <el-form-item label="培训学时">
          <el-input v-model="form.period" :style="inputWidth" />
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <el-form-item label="培训方式">
          <el-input v-model="form.form" :style="inputWidth" />
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <el-form-item label="培训内容">
          <el-input v-model="form.content" :style="inputWidth" />
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <el-form-item label="培训成绩">
          <el-input type="number" v-model="form.grade" :style="inputWidth" />
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <el-form-item label="培训费用">
          <el-input v-model="form.cost" :style="inputWidth" />
        </el-form-item>
      </el-col>
      <el-col>
        <el-form-item label="备注">
          <el-input type="textarea" :rows="2" v-model="form.remark" />
        </el-form-item>
      </el-col>
      <el-col class="tl-center">
        <el-button @click="handleUpdate" type="primary">修改</el-button>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
import { updateUserTrain, getUserTrain } from '@/api/archives'
import { setSession, getSession } from '@/utils/util'
export default {
  data() {
    return {
      form: {},
      labelPosition: 'right',
      inputWidth: {
        width: '80%'
      }
    }
  },
  methods: {
    handleUpdate() {
      updateUserTrain(this.form).then(res => {
        console.log('res', res)
      })
    },
    handleShowHistory() {
      this.$emit('showHistory', 'examine')
    }
  },
  created() {
    if (this.userRow) {
      setSession('userRow', this.userRow)
    } else {
      this.userRow = getSession('userRow')
    }

    getUserTrain(this.userRow.userId).then(res => {
      console.log('res', res)
      this.form = Object.assign({}, res.data)
      this.$set(this.form, 'userId', this.userRow.userId)
    })
  }
}
</script>
